var express = require('express');
var router = module.exports = express.Router();

var _userDao = require('../dao/userDao');
var cookieSession = require('../util/base').cookieSession();

router.use(cookieSession);
var code= '123123';
// 检查
router.post('/check',function (req,resp,next) {
	_userDao.checkedRegisterInfo(req, resp, next);
});

// 注册
router.post('/',function (req,resp,next) {
	
	// 验证码不正确
	console.error(req.body);
	
	if(code !== req.body.msg_code){
		resp.json({
			hasError: true,
			errMsg: '验证码不正确'
		});
		return;
	}
	
	_userDao.register(req, resp, next);
});

// 再次获取验证码
router.get('/:tel',function (req,resp,next) {
	console.error(req.params);
	code = '123321';
	/*resp.json({
		hasError: true,
		errMsg: '服务器未知错误'
	})*/
	resp.json({
		hasError: false,
	 	errMsg: null
	})
});